#include <QCoreApplication>
#include <QDebug>
#include <QDateTime>
#include <QTcpSocket>
#include <QUrl>

#include "curl_download_tool.h"

int main(int argc, char **argv)
{
    QCoreApplication a(argc, argv);
    // https://filewh.uniontech.com/seafhttp/files/d1f86c93-cbf4-4576-bf4f-93bc5b3709a4/udcp-esm-tools_1.7.2.12%2B1-1_arm64.deb

    const qint64 downloadStartMSecs = QDateTime::currentDateTime().toMSecsSinceEpoch();
    // CurlDownloadTool downloadTool;
    // int statusCode;
    // bool result = downloadTool.download(statusCode,
    //                                     "https://filewh.uniontech.com/seafhttp/files/d1f86c93-cbf4-4576-bf4f-93bc5b3709a4/udcp-esm-tools_1.7.2.12%2B1-1_arm64.deb",
    //                                     "/home/yang/test_curl/test");

    QUrl url("https://dldir1.qq.com/weixin/Windows/WeChatSetup.exe");
    qInfo() << url << url.host() << url.port();

    QTcpSocket socket;
    QObject::connect(&socket, &QTcpSocket::connected, [&]() { qInfo() << "111111"; socket.write("method: GET\t\nHost: dldir1.qq.com\r\nAccept-Encoding: gzip, deflate, br\r\nConnection: keep-alive"); });
    QObject::connect(&socket, &QTcpSocket::stateChanged, [](QAbstractSocket::SocketState socketState) { qInfo() << "111111" << socketState; });
    QObject::connect(&socket, &QTcpSocket::readyRead, [&]() { qInfo() << socket.readAll(); });

    socket.connectToHost(url.host(), url.port(80));

    return a.exec();
}